@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header clearfix">
                  <span class="float-left">交易查询 ({{ $transactions->total() }}条记录)</span>
                  <span class="float-right">最后同步时间: {{ isset($last_sync->created_at) ? $last_sync->created_at : '暂未进行同步' }}</span>
                </div>

                <div class="card-body">
                    <form>
                      <div class="form-row align-items-center">
                        <div class="col-auto">
                          <label class="sr-only" for="inlineFormInput">转发者</label>
                          <input type="text" name="from" class="form-control mb-2" id="inlineFormInput" value="{{ request()->get('from') }}" placeholder="转发者">
                        </div>
                        <div class="col-auto">
                          <label class="sr-only" for="inlineFormInput">Example select</label>
                          <select name="type" class="form-control mb-2" id="inlineFormInput">
                            <option @if (request()->get('type') == 0) selected @endif value="0">全部</option>
                            <option @if (request()->get('type') == 1) selected @endif value="1">以太坊交易</option>
                            <option @if (request()->get('type') == 2) selected @endif value="2">代币交易</option>
                          </select>
                        </div>
                        <div class="col-auto">
                          <div class='input-group'>
                              <input type='text' name="start_date" value="{{ request()->get('start_date') }}"  id='datetimepicker1' placeholder="开始时间" class="form-control mb-2 datepicker-here" data-language="en" />

                            
                              <input type='text' name="end_date" value="{{ request()->get('end_date') }}"  id='datetimepicker2' placeholder="结束时间" class="form-control mb-2 datepicker-here" data-language="en" />

                          </div>
                        </div>
                        <div class="col-auto">
                          <button type="submit" class="btn btn-primary mb-2">搜索</button>
                        </div>
                      </div>
                    </form>

                    <table class="table table-hover">
                      <thead>
                        <tr>
                          <th scope="col">交易哈希</th>
                          <th scope="col">区块</th>
                          <th scope="col">交易时间</th>
                          <th scope="col">转出者</th>
                          <th scope="col">接收者</th>
                          <th scope="col">转出以太坊数量</th>
                        </tr>
                      </thead>
                      <tbody>
                        @foreach ($transactions as $transaction)
                        <tr>
                          <th scope="row"><a href="{{ route('transaction.show', $transaction->id) }}">{{ substr($transaction->hash, 0, 12) . '...' }}</a></th>
                          <td>{{ $transaction->blockNumber }}</td>
                          <td>{{ date('Y-m-d H:i:s', $transaction->timeStamp) }}</td>
                          <td>{{ substr($transaction->from, 0, 12) . '...' }} 
                          </td>
                          <td>{{ substr($transaction->to, 0, 12) . '...' }}</td>
                          <td>{{ $transaction->value / bcpow(10, 18) }} Ether</td>
                        </tr>
                        @endforeach
                      </tbody>
                    </table>

                </div>
                <div class="col-auto">

                    {{ $transactions->links() }}
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
  $(function() {
    $('#datetimepicker1').datepicker();
    $('#datetimepicker2').datepicker();
  });
</script>
@endsection
